/*
 * Copyright 2012 The Eventio Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.eventio;

import java.util.concurrent.Callable;
import java.util.concurrent.Executor;

/**
 * The {@link EventExecutor} provides various ways of delegating work to a pool
 * of threads, in order to avoid blocking the {@link EventDispatcher} Thread.
 * Reactions to be executed after the different tasks are guaranteed to be
 * executed in the dispatcher thread.
 * <p>
 * In order to execute task reactions in the {@link EventDispatcher} thread, the
 * executor needs to subscribe local events. This implies that calls to the
 * different execution methods need to be called from the dispatcher thread.
 * 
 * @author steph
 * 
 */
public interface EventExecutor extends Executor {

	/**
	 * Derives a {@link Resource} form the given {@link Loadable}, by executing
	 * the {@link Loadable#load(Object)} method in the executor pool.
	 * 
	 * @param loadable
	 * @return
	 */
	<P, V> Resource<P, V> newResource(Loadable<P, V> loadable);

	/**
	 * Executes the given task, and passes it to the provided {@link Reaction}
	 * when the result is available.
	 * 
	 * @param task
	 * @param react
	 */
	<V> void execute(Callable<V> task, Reaction<Result<V>> react);

	<V> void execute(CallableReaction<V> callReac);

	<P, V> void execute(P param, Loadable<P, V> c, Reaction<Result<V>> react);

	<P, V> void execute(P param, LoadableReaction<P, V> callReac);

}
